<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8" %>
<%@page import="org.ipo.mm.web.util.ConstantManager, java.util.Collection, org.ipo.mm.web.util.security.SecurityManager" %>
<%@taglib prefix="l" uri="http://struts.apache.org/tags-logic" %>
<%@taglib prefix="b" uri="http://struts.apache.org/tags-bean" %>
<%@taglib prefix="h" uri="http://struts.apache.org/tags-html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%String readOnlyStr = (String) session.getAttribute("readOnly");%>

<h1>
    <% if (readOnlyStr.equals("true")) {%>
    <b:message key="families_show_read_mode"/>
    <%} else {%>
    <b:message key="families_show_edit_mode"/>
    <%}%>
</h1>
<div id="createFamily" class="displayNone">
    <%
                Collection<Integer> privileges = (Collection<Integer>) request.getSession().getAttribute(ConstantManager.SESSION_USER_PRIVILEGES);
                if (privileges.contains(SecurityManager.CREATE_IFAMILY_PRIVILEGE)) {%>

    <h:link styleClass="createNew" action="/protected/dispatch?method=showCreateFamilyForm"><b:message key="families_create"/></h:link><br>

    <%}%>
</div>

<div>
    <table  id="familyListTable" class="display sortableTable">
        <thead>
            <tr>
                <th scope="col"><b:message key="families_name"/></th>
                <th scope="col"><b:message key="inst_find_inst"/></th>
    <!--<th scope="col"><b:message key="gen_note"/></th>-->
                <%if (readOnlyStr.equals("false")) {%>
                <th><b:message key="gen_action"/></th>
                <%}%>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th scope="col"><b:message key="families_name"/></th>
                <th scope="col"><b:message key="inst_find_inst"/></th>
                            <!--<th scope="col"><b:message key="gen_note"/></th>-->
                <% if (readOnlyStr.equals("false")) {%>
                <th><b:message key="gen_action"/></th>
                <%}%>
            </tr>
        </tfoot>
        <tbody>
            <l:iterate id="family" name="showFamilies.families" scope="request">
                <tr>
                    <td>
                        <% if (readOnlyStr.equals("false")) {%>
                        <p class="link"
                           onclick="getHtmlAjax('<%= request.getContextPath()%>/protected/dispatch.do?method=showUpdateFamilyForm&fid=${family.id}','#familyDialog','#familyForm');">
                            <b:write name="family" property="name"/>
                        </p>
                        <%} else {%>
                        <p class="link"
                           onclick="getHtmlAjax('<%= request.getContextPath()%>/protected/dispatch.do?method=viewFamilyForm&fid=${family.id}','#familyDialog','#familyForm');">
                            <b:write name="family" property="name"/>
                        </p>
                        <%}%>
                    </td>
                    <td>
                        <h:link action="/protected/institution_search">
                            <h:param name="fid"  value="${family.id}"/>
                            <h:param name="readOnly"  value="true"/>
                            <span><b:message key="inst_find_inst"/> - <b:write name="family" property="name"/></span>
                        </h:link>
                    </td>
                    <% if (readOnlyStr.equals("false")) {%>
                    <td>
                        <%if (privileges.contains(SecurityManager.DELETE_IFAMILY_PRIVILEGE)) {%>
                        <h:link styleClass="delete"
                                action="/protected/dispatch?method=deleteFamily"
                                paramId="fid"
                                paramName="family"
                                paramProperty="id"
                                onclick="return confirm('Are you sure you want to delete this item?/Da li ste sigurni da zelite da izbrisete ovaj entitet?')">
                            <b:message key="gen_delete"/>
                        </h:link>
                        <%}%>
                        <!-- SECURITY CONSTRAINT USER CAN EDIT ONLY ENTITIES HE CREATED -->
                        <%--
                        <c:choose>
                            <c:when test="${(USER == family.user) || (USER.type == USER_TYPE_ADMIN_PA)}">
                                <h:link  styleClass="details" action="/protected/dispatch?method=showUpdateFamilyForm"
                                        paramId="fid" paramName="family" paramProperty="id">
                                    <b:message key="gen_update" />
                                </h:link>
                            </c:when>
                        </c:choose>
                        --%>
                        <%--
                        EMAIL LINK DISABLED
                        <l:iterate id="email_set" name="MAIL_TO_FAMILY_${family.id}">
                            <a  class="email" href="${email_set}">Email</a>
                        </l:iterate>
                        --%>
                        <!--
                        <%if (privileges.contains(SecurityManager.EDIT_IFAMILY_PRIVILEGE)) {%>
                        <h:link  styleClass="details" action="/protected/dispatch?method=showUpdateFamilyForm"
                                 paramId="fid" paramName="family" paramProperty="id">
                            <b:message key="gen_update" />
                        </h:link>

                        <%}%>
					-->
                    </td>
                    <%}%>
                </tr>
            </l:iterate>
        </tbody>
    </table>
</div><!--tabela-->
<div id="familyDialog" class="dialog" title="">
</div>
<div id ="messageregion"></div>


<script type="text/javascript">	
    function cancelForm(){
        $(".dialog").dialog('close');
    }
</script>

